package cn.newstrength.qiyiming.step;

//import cn.newstrength.wtdf.plugin.obj.JwtSubject;
import cn.newstrength.wtdf.web.databus.DataContext;
import cn.newstrength.wtdf.web.exception.PAIException;
import cn.newstrength.wtdf.web.processor.Operation;
import cn.newstrength.wtdf.web.processor.OperationStep;
import cn.newstrength.wtdf.web.util.StepUtils;
import com.alibaba.fastjson.JSON;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;

/**
 * 讲总线上的就参数，作为调用核心的参数，并放入登录用户agentCode
 */

public class QYMSendMessageStep implements OperationStep {
    private final static Logger logger = LoggerFactory.getLogger(QYMSendMessageStep.class);

    @Override
    public int excute(Operation oper) throws PAIException {
        // 1.获取公用变量
        DataContext dc = oper.getContext();

        Map<String, Object> input = StepUtils.getInputValue(oper);
        Map<String, Object> sendMap = new HashMap<String, Object>();


        for(String key :input.keySet()) {
            if(!key.startsWith("_")) {
                sendMap.put(key, input.get(key));
            }
        }
        String preInfo = sendMap.get("preInfo")+"";
        if(preInfo!=null) {
            String s = preInfo.replaceAll("\\\\", "");
            sendMap.replace("preInfo",s);
        }
        String JsonString =  JSON.toJSONString(sendMap);
        logger.info("接口调用参数：" +JsonString);

        oper.setTranStepSuccResult(JsonString);//stepID作为result的name

        return 0;
    }

    @Override
    public int init(Map<String, String> param) {

        return 0;
    }
}
